import 'package:flutter/cupertino.dart';
import 'package:imember/Util/MyColor.dart';
import 'package:imember/Widget/MyImage.dart';
import 'package:imember/Widget/MyPage.dart';

class HistoryRecord extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return HistoryRecordState();
  }
}

class HistoryRecordState extends State {
  @override
  Widget build(BuildContext context) {
    return MyPage(
        Container(
          child: true
              ? Container(
                  child: Column(
                  children: [
                    Container(
                        height: 57,
                        alignment: Alignment.centerLeft,
                        padding: EdgeInsets.only(left: 365),
                        child: Text("操作時間", style: TextStyle(fontSize: 20, color: MyColor.C70))),
                    Container(height: 2, color: MyColor.DD),
                    Expanded(
                        child: ListView.separated(
                      padding: EdgeInsets.all(0),
                      itemCount: 10,
                      itemBuilder: (BuildContext context, int index) {
                        return ItemRecord();
                      },
                      separatorBuilder: (BuildContext context, int index) {
                        return Container(height: 2, color: MyColor.DD);
                      },
                    ))
                  ],
                ))
              : Center(child: Text("目前尚無紀錄", style: TextStyle(fontSize: 30, color: MyColor.C70, fontWeight: FontWeight.bold))),
        ),
        title: "歷史紀錄");
  }
}

class ItemRecord extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _ItemRecord();
  }
}

class _ItemRecord extends State {
  bool showChild = false;

  switchChildVisible() {
    setState(() {
      showChild = !showChild;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
        padding: EdgeInsets.fromLTRB(0, 8, 0, 8),
        child: Column(children: [
          ItemRecord2("盤點調整", "2020/01/11  20:58", showChild: showChild, onTap: switchChildVisible),
          Visibility(
              visible: showChild,
              child: ListView.builder(
                  shrinkWrap: true,
                  padding: EdgeInsets.all(0),
                  physics: NeverScrollableScrollPhysics(),
                  itemCount: 5,
                  itemBuilder: (BuildContext context, int index) {
                    return ItemRecord2("庫存盤點", "2020/01/11  20:58", showIcon: false, onTap: () {});
                  }))
        ]));
  }
}

class ItemRecord2 extends StatelessWidget {
  bool? showIcon;
  bool? showArrow;
  bool? showChild;
  Function() onTap;
  String title;
  String time;

  ItemRecord2(this.title, this.time, {this.showIcon, this.showChild, this.showArrow, required this.onTap});

  @override
  Widget build(BuildContext context) {
    showIcon = showIcon ?? true;
    showArrow = showArrow ?? true;
    showChild = showChild ?? false;
    return GestureDetector(
      onTap: onTap,
      behavior: HitTestBehavior.opaque,
      child: Row(children: [
        Container(width: 37),
        showIcon! ? LocalImage(showChild! ? "ic_sub_g.png" : "ic_add_g.png", width: 20, height: 20) : Container(width: 20),
        Container(
          width: 250,
          alignment: Alignment.center,
          child: Text(title, style: TextStyle(fontSize: 20, color: MyColor.Black)),
        ),
        Text(time, style: TextStyle(fontSize: 20, color: MyColor.Black, fontWeight: FontWeight.bold)),
        Container(width: 50),
        showArrow! ? LocalImage("ic_arrow_r.png", width: 48, height: 48) : Container(height: 48),
      ]),
    );
  }
}
